<?php $this->placeholder('container-class')->set('post_ad property residential')?>
<?php $this->JQuery()->javascriptCaptureStart()?>
jQuery(function() {
    $('#agency_owner-1').click(function() {
        $('#agentname_label').show();
        $('#agentphone_label').show();
        $('#agentmail_label').show();
        $('#id_input_agent').show();
        $('#sole_agency_label').show();
        
        $('#ownername_label').hide();
        $('#ownerphone_label').hide();
        $('#ownermail_label').hide();
    });

    $('#agency_owner-0').click(function() {
        $('#agentname_label').hide();
        $('#agentphone_label').hide();
        $('#agentmail_label').hide();
        $('#id_input_agent').hide();photos
        $('#sole_agency_label').hide();

        $('#ownername_label').show();
        $('#ownerphone_label').show();
        $('#ownermail_label').show();
    });

    $('#add_more_btn').click(function() {               
        if ($('#add_more_checkbox').attr('value') == 1) {
            $('#add_more_checkbox').attr('value',0);
        }
        else {
            $('#add_more_checkbox').attr('value',1);
        }
        $('#add_more').toggle();
        return false;
    });

    $('#sale_lease').click(function() {
        $('#sale_lease_panel').toggle();
    });

    $('#rent_property_too').click(function() {
        $('#rent_property_too_panel').toggle();
    });
    
    if ($('#sale_lease:checked').val() == 1) {
        $('#sale_lease_panel').show();
    }
    else {
        $('#sale_lease_panel').hide();
    }

    if ($('#add_more_checkbox').attr('value') == 0) {
        $('#add_more').show();
    }
    else {
        $('#add_more').hide();
    }

    // Control for Title
    $('input#title').keydown(function(event) {
        var charLength = 100 - $(this).val().length;
        if (charLength <0) {
            if ( event.keyCode == 8 || event.keyCode == 46 ) {

            } else {
                return false;
            }
        }
        else {
            $('span#counter_title').html('<em>'+charLength + '</em> characters remaining');
        }
    });

    // Control for Description
    $('textarea#description').keydown(function(event) {
        var charLength = 3000 - $(this).val().length;
        if (charLength <0) {
            if ( event.keyCode == 8 || event.keyCode == 46 ) {

            } else {
                return false;
            }
        }
        else {
            $('span#counter_description').html('<em>'+charLength + '</em> characters remaining');
        }
    });

    //Online Only Area
    if ($j("#area_l1").val() == "4cbe455a8835c17c10060000") {
        $j("#district_div").hide();
    }
    else {
        $j("#district_div").show();
    }


    $j('#preview_link').click(function() {
        var action = $j('#listing_form').attr('action');
        $j('#listing_form').attr('action', '<?php echo $this->preview_link?>');
        $j('#listing_form').attr('target','_blank');
        $j('#listing_form').submit();
        $j('#listing_form').attr('action', action);
        $j('#listing_form').attr('target','_self');
        return false;
    });
    
});
<?php $this->JQuery()->javascriptCaptureEnd()?>

<form action="<?php echo $this->escape($this->form->getAction()) ?>" method="<?php echo $this->escape($this->form->getMethod())?>" id="listing_form"  enctype="multipart/form-data">
    <fieldset>
          <legend><?php echo $this->t('Create Your Ad');?></legend>
          <div class="required">Required Information</div>
            <div class="category desc">
              <label>Selected Categories
                  <?php /*if (!isset($_GET['id'])):?>
                    (<a href="<?php echo $this->geturl('post-an-ad', 'listing', null, null, array('category' => $_GET['category'], 'change' => 1))?>">Change</a>)
                  <?php endif;*/?>
                  :</label>
              <ul>
                  <?php foreach($this->category as $cat):?>
                      <li>
                          <?php
                            $tmp = array();
                            foreach($cat->getParentTree() as $p) {
                                $tmp[] = $p->name;
                            }
                            echo implode(' &gt; ', $tmp);
                          ?>
                      </li>
                  <?php endforeach;?>
             </ul>
            </div>
            <input type="hidden" name="adid" id="adid" value="<?php echo $this->adid?>">
            <?php foreach($this->category as $cat):?>
                <input type="hidden" name="category[]" value="<?php echo $cat->_id?>">
            <?php endforeach;?>

            <div class="title text">
              <label class="required"><?php echo $this->t('Title')?></label>
              <span id="counter_title"><?php echo $this->t('<em>100</em> characters remaining')?></span>
              <?php echo $this->form->title ?>
              <?php if (!empty($_POST['title'])) { ?>
              <?php if (preg_match("#.[a-z0-9._-]+@[a-z0-9._-]{2,}\.[a-z]{2,4}.#", $_POST['title'])) { ?>
                  <ul class="errors"><li><?php echo $this->t('Please remove email')?></li></ul>
              <?php } } ?>
            </div>

            <div class="custom_info">          
                <div class="custom_info_1">
                    <!--<div class="identity radio">
                    <?php
                          //if (isset($this->loggedin_user)) {
                              //$user = $this->loggedin_user;
                              //if ($user->type == Model_User::AGENT) {
                                  ?>
                                  <input name="agency_owner" value="1" type="hidden">
                                  <?php
                              //}
                              //elseif ($user->type == Model_User::PERSONAL) {
                                  ?>
                                  <input name="agency_owner" value="0" type="hidden">
                                  <?php
                              //}
                          //}
                          //else {
                              //echo $this->form->agency_owner;
                         // }
                    ?>
                    </div>
                          <?php
                          //if (isset($this->loggedin_user)) {
                              //$user = $this->loggedin_user;?>
                              <input name="agent_name"    value="<?php //echo $user->firstname.' '.$user->lastname;?>"   type="hidden">
                              <input name="agent_phone"   value="<?php //echo $user->phone;?>"      type="hidden">
                              <input name="agent_email"   value="<?php //echo $user->email;?>"      type="hidden">
                              <?php //if ($user->type == Model_User::AGENT) { ?>
                                    <input name="agent_id"      value="<?php //echo $user->agent_id;?>"   type="hidden">
                                  //<?php
                              //}
                          //}
                          //else {?>
                                <div class="sole_agency checkbox" id="sole_agency_label" style="display:none;">                                    
                                    <?php //echo $this->form->sole_agency ?>
                                    <label><?php //echo $this->t('Sole Agency')?></label>
                                </div>
                                <div class="agency_name text">
                                    <label id="agentname_label" style="display:none;"><?php //echo $this->t('Agent Name')?></label>
                                    <label id="ownername_label"><?php //echo $this->t('Owner Name')?></label>
                                    <?php //echo $this->form->agent_name ?>
                                </div>
                                <div class="agency_id text" id="id_input_agent" style="display:none;">
                                    <label><?php //echo $this->t('Agent ID')?></label>
                                    <?php //echo $this->form->agent_id ?>
                                </div>
                                <div class="agency_phone text">
                                    <label id="agentphone_label" style="display:none;"><?php //echo $this->t('Agent Phone Number')?></label>
                                    <label id="ownerphone_label"><?php //echo $this->t('Owner Phone Number')?></label>
                                    <?php //echo $this->form->agent_phone ?>
                                </div>
                                <div class="agency_email text">
                                    <label id="agentmail_label" style="display:none;" class="required"><?php echo $this->t('Agent Email')?></label>
                                    <label id="ownermail_label" class="required"><?php //echo $this->t('Owner Email')?></label>
                                    <?php //echo $this->form->agent_email ?>
                                </div>
                          <?php //} ?>-->
                          <div class="desc price">
                            <h3>Sale or Rent Price</h3>
                            <p>Please input <em>Sales Price</em> and/or <em>Rent Price</em> below.</p><p>At least one is required.</p>
                          </div>

                          <div class="price">
                            <ul>
                            <li>
                          <div class="sale_price price text">
                                <span><?php echo $this->t('Sale Price (Numbers only)')?></span>
                                <label><?php echo $this->t('HKD')?></label>
                                <label><?php echo $this->form->sale_price ?></label>
                            </div>
                            <!--<div class="price_negotiable checkbox">
                                <span><?php //echo $this->form->price_negotiable ?></span>
                                <label><?php //echo $this->t('Price negotiable')?></label>
                            </div>-->
                            <div class="price_negotiable checkbox">
                                <?php echo $this->form->sale_lease ?>
                                <label><?php echo $this->t('Sell with a Lease')?></label>
                            </div>
                            <div style="display:none" id="sale_lease_panel">
                                <div class="current_lease_price price text">
                                    <span><?php echo $this->t('Current Lease Price (Numbers only)')?></span>
                                    <label><?php echo $this->t('HKD')?></label>
                                    <label><?php echo $this->form->current_lease_price ?></label>
                                </div>
                                <div class="lease_end_date text">
                                    <label ><?php echo $this->t('Lease End Date')?></label>
                                    <?php echo $this->form->lease_enddate ?>
                                </div>
                            </div>
                            </li>
                            <li>
                            <!--<div class="sell checkbox">
                                <span><?php //echo $this->form->rent_property_too ?></span>
                                <label><?php //echo $this->t('I would like to rent my Property too')?></label>
                            </div>-->
                            <div class="price_general price text">
                                <span><?php echo $this->t('Rent price (Numbers only)')?></span>
                                <label><?php echo $this->t('HKD')?></label>
                                <label><?php echo $this->form->rent_price ?></label>
                            </div>
                            <div class="mgmt_govt checkbox">
                                <?php echo $this->form->rent_include_mngt_fee ?>
                                <label><?php echo $this->t('Rent Price includes Mgmt Fee & Govt Rate')?></label>
                            </div>
                            </li>
                            </ul>
                            </div>                        
                            
                </div>
                <div class="custom_info_2">
                    <div class="area select">
                        <label class="required"><?php echo $this->t('Area')?></label>
                        <?php echo $this->form->area_l1 ?>
                    </div>
                    <div class="district select" id="district_div">
                      <label class="required"><?php echo $this->t('District')?></label>
                        <?php echo $this->form->area_l2 ?>
                    </div>
                    <div class="address textarea">
                      <label class="required">Building Name, Street Address</label><span>Location is displayed in your Ad</span>
                        <?php echo $this->form->address ?>
                    </div>
                    <div class="bedroom select">
                        <label class="required"><?php echo $this->t('Bedrooms')?></label>
                        <?php echo $this->form->bedroom?>
                    </div>
                    <div class="size text">
                        <label class="required">Size (sq.ft)</label><span>Numbers only (e.g. 1500) Will display as 1,500sqft</span>
                        <?php echo $this->form->size?>
                    </div>
                </div>
            </div>

            <div class="description textarea">
                  <label class="required"><?php echo $this->t('Description')?></label>
                  <span id="counter_description"><?php echo $this->t('<em>3000</em> characters remaining')?></span>
                  <?php echo $this->form->description?>
                  <?php if (!empty($_POST['description'])) { ?>
                  <?php if (preg_match("#.[a-z0-9._-]+@[a-z0-9._-]{2,}\.[a-z]{2,4}.#", $_POST['description'])) { ?>
                      <ul class="errors"><li><?php echo $this->t('Please remove email')?></li></ul>
                  <?php } } ?>
                  <span id="info_description"><?php echo $this->t('To prevent spam, do not enter any email addresses.')?></span>
            </div>

            <div class="property_info_more button desc" id="add_more_btn">
                <?php echo $this->form->add_more_checkbox?>
                <button id="add_more_btn"><?php echo $this->t('Add More')?></button>
                <p><?php echo $this->t('Click to "Add More" specifications to your Property Info and Building Info')?></p>
            </div>

            <div class="property_info_more optional" id="add_more" style="display:none;">
                <div class="bathrooms select">
                    <label><?php echo $this->t('Bathrooms')?></label>
                    <?php echo $this->form->bathroom?>
                </div>
                <div class="building_type select">
                    <label><?php echo $this->t('Building Type')?></label>
                    <?php echo $this->form->building_type?>
                </div>
                <div class="building_age select">
                    <label><?php echo $this->t('Building Age (Year)')?></label>
                    <?php echo $this->form->building_age?>
                </div>
                <div class="floor_zone select">
                    <label><?php echo $this->t('Ground Zone')?></label>
                    <?php echo $this->form->floor_zone?>
                </div>

                <div class="facilities checkbox">
                    <span><?php echo $this->t('Facilities')?></span>
                    <?php echo $this->form->facilities?>
                </div>

                <div class="conditions checkbox">
                    <span><?php echo $this->t('Conditions')?></span>
                    <?php echo $this->form->conditions?>
                </div>
                <div class="view checkbox">
                    <span><?php echo $this->t('View')?></span>
                    <?php echo $this->form->views?>
                </div>
                <div class="rooms checkbox">
                    <span><?php echo $this->t('Rooms')?></span>
                    <?php echo $this->form->rooms?>
                </div>
                <div class="outdoor checkbox">
                    <span><?php echo $this->t('Outdoor')?></span>
                    <?php echo $this->form->outdoor?>
                </div>
                <div class="layout checkbox">
                    <span><?php echo $this->t('Layout')?></span>
                    <?php echo $this->form->layout?>
                </div>
                <div class="others text">
                    <label><?php echo $this->t('Others')?></label>
                    <?php echo $this->form->other?>
                </div>
                <div class="management_fee price text">
                    <span><?php echo $this->t('Management Fee / month (Numbers only)')?></span>
                    <label><?php echo $this->t('HKD')?></label>
                    <label><?php echo $this->form->management_fee?></label>
                </div>
                <div class="government_fee price text">
                    <span><?php echo $this->t('Government Rate / quarter (Numbers only)')?></span>
                    <label><?php echo $this->t('HKD')?></label>
                    <label><?php echo $this->form->government_fee?></label>
                </div>
           </div>


           <?php echo $this->Partial('/index/photo-uploader.phtml', 'listing', array('listing' => $this->listing));?>

            <div class="button_em">
                <button><?php echo $this->t('Post Your Ad')?></button>
            </div>

            <p class="preview button">
                <button id="preview_link"><?php echo $this->t('Preview Your Ad')?></button>
            </p>
        </fieldset>
    </form>
